
/*
    Software License

    Copyright (C) 2021-05-24  Xoronos

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, version 3.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <https://www.gnu.org/licenses/>.
*/

/*
    Liabilities

    The software is provided "AS IS" without any warranty of any kind, either expressed,
    implied, or statutory, including, but not limited to, any warranty that the software
    will conform to specifications, any implied warranties of merchantability, fitness
    for a particular purpose, and freedom from infringement, and any warranty that the
    documentation will conform to the software, or any warranty that the software will
    be error free.

    In no event shall Xoronos be liable for any damages, including, but not limited to,
    direct, indirect, special or consequential damages, arising out of, resulting from,
    or in any way connected with this software, whether or not based upon warranty,
    contract, tort, or otherwise, whether or not injury was sustained by persons or
    property or otherwise, and whether or not loss was sustained from, or arose out of
    the results of, or use of, the software or services provided hereunder.

    To request the provided software under a different license you can contact us at
    support@xoronos.com
*/

#include "steg_data.h"

uint16_t steg_encode4( uint8_t num4, uint16_t num16
 )
{

    return steg_enc[( ( num4 << 16 ) | num16 )];

}

uint8_t steg_decode4( uint16_t num16
 )
{

    return steg_dec[num16];

}

uint32_t steg_encode( uint8_t in, uint32_t medium
 )
{

    uint32_t res;

    res = 0;

    // upper
    res =
        ( uint32_t ) ( steg_encode4( ( in & 0xf0 ) >> 4, ( uint16_t ) ( ( medium & 0xffff0000 ) >> 16 ) ) <<
                       16 );
    // lower
    res = res | ( uint32_t ) ( steg_encode4( in & 0x0f, medium & 0x0000ffff ) );

    return res;

}

uint8_t steg_decode( uint32_t in
 )
{

    uint8_t res;

    res = 0;

    // upper
    res = ( uint8_t ) ( steg_decode4( ( uint16_t ) ( ( in & 0xffff0000 ) >> 16 ) ) << 4 );
    // lower
    res = res | steg_decode4( ( uint16_t ) ( in & 0x0000ffff ) );

    return res;

}

